<template>
  <div
    class="echart"
    ref="echartDivRef"
    :style="{ width: width, height: height }"
  ></div>
</template>

<script lang="ts" setup>
import { ref, onMounted, defineProps, withDefaults } from 'vue';

import type { EChartsOption } from 'echarts';
import echartHook from '../hook/useEchart';
const props = withDefaults(
  defineProps<{
    options: EChartsOption;
    width?: string;
    height?: string;
  }>(),
  {
    height: '360px',
    width: '100%'
  }
);

const echartDivRef = ref<HTMLElement>();

onMounted(() => {
  const { setOptions } = echartHook(echartDivRef.value!);
  setOptions(props.options);
});
</script>

<style lang="less" scoped>
.echart {
  color: red;
}
</style>
